export default [
    {
        // 主页
        path: '/home',
        component: () => import('@/views/Home/index.vue'),
        name: 'home',
        meta: {
            show: true,
            login: true
        }
    },
    {
        // 登陆
        path: '/login',
        component: () => import('@/views/Login/index.vue'),
        meta: {
            show: false,
            login: true
        }
    },
    {
        // 注册
        path: '/register',
        name: 'register',
        component: () => import('@/views/Register/index.vue'),
        meta: {
            show: false,
            login: true
        }
    },
    {
        // 搜索
        path: '/search/:keyword?',//这个？表示次params参数是否必须的，否则keyword没有值则不显示search路径名称
        name: 'search',
        component: () => import('@/views/Search/index.vue'),
        meta: {
            show: true,
            login: true
        },

    },
    {
        // 商品详情
        path: '/detail/:skuId',
        component: () => import('@/views/Detail/index.vue'),
        meta: {
            show: true,
            login: true
        },

    },
    {
        // 加入购物车成功页面
        path: '/addCartSuccess',
        name: 'addCartSuccess',
        component: () => import('@/views/AddCartSuccess/index.vue'),
        meta: {
            show: true,
            login: true
        },

    },
    {
        // 购物车页面
        path: '/shopCart',
        component: () => import('@/views/ShopCart/index.vue'),
        meta: {
            show: true,
            login: true
        },
    },
    {
        // 订单页面
        path: '/trade',
        component: () => import('@/views/Trade/index.vue'),
        meta: {
            show: true,
            login: false
        },
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 只有从购物车才能来到订单页面
            if (from.path === '/shopCart') {
                next();
            } else {
                // 停留原地
                next(false)
            }
        }
    },
    {
        // 支付页面
        path: '/pay',
        component: () => import('@/views/Pay/index.vue'),
        meta: {
            show: true,
            login: false
        },
        beforeEnter: (to, from, next) => {
            if (from.path === '/trade') {
                next();
            } else {
                next(false)
            }
        }
    },
    {
        // 支付页面
        path: '/paySuccess',
        component: () => import('@/views/PaySuccess/index.vue'),
        meta: {
            show: true,
            login: false
        }
    },
    {
        // 个人中心页面
        path: '/center',
        component: () => import('@/views/Center/index.vue'),
        meta: {
            show: true,
            login: false
        },
        children: [
            {
                // 我的订单
                path: 'myOrder',
                component: () => import('@/views/Center/MyOrder/index.vue'),
            },
            {
                // 团购订单
                path: 'ourOrder',
                component: () => import('@/views/Center/OurOder/index.vue'),
            },
            {
                // 初始化到我的订单页面
                path: '/center',
                redirect: '/center/myOrder'
            }
        ]
    },
    {
        // 访问项目时重定向到home首页
        path: '*',
        redirect: '/home'
    },
]